-- nart ddc 核心表

use nart_blockchain;

set names utf8mb4;
set foreign_key_checks = 0;

-- ----------------------------
-- table structure for chain
-- ----------------------------
drop table if exists `chain`;
create table `chain`
(
    `id`                bigint  not null,
    `chain_id`          integer not null comment '链id',
    `opb_chain_id`      integer not null comment '开发联盟链id',
    `explorer`          varchar(100) character set utf8mb4 default '' comment '区块链浏览器',
    `name`              varchar(100) character set utf8mb4 default '' comment '开发联盟链名称',
    `gateway`           varchar(200) character set utf8mb4 default '' comment '网关',
    `ddc721_address`    varchar(100) character set utf8mb4 default '' comment '721智能合约地址',
    `ddc1155_address`   varchar(100) character set utf8mb4 default '' comment '1155智能合约地址',
    `authority_address` varchar(100) character set utf8mb4 default '' comment '权限代理智能合约地址',
    `charge_address`    varchar(100) character set utf8mb4 default '' comment '计费智能合约地址',
    `del_flag`          char(1) character set utf8mb4      default '0' comment '删除标志',
    primary key (`id`) using btree
) engine = innodb
  default charset = utf8mb4
  collate = utf8mb4_general_ci comment ='区块链';

begin;
insert into `chain`
values (1, 5555, 4, 'http://explorer.ope.bsnbase.com/', '文昌链（基于irita v3.1.0）-sm2/secp256k1',
        'https://opbningxia.bsngate.com:18602/api/edf44f6dcaef47a38b3743fa3837820c/rpc',
        '0xad3B52B4F4bd9198DC69dD9cE4aC9846667461a2', '0x061e59c74815994DAb4226a0D344711F18E0F418',
        '0xCa97bF3a19403805d391102908665b16B4d0217C', '0x466D5b0eA174a2DD595D40e0B30e433FCe6517F5', '0');
commit;


-- ----------------------------
-- table structure for account
-- ----------------------------
drop table if exists `account`;
create table `account`
(
    `id`                    bigint                         not null,
    `chain_id`              bigint                         not null comment '链id',
    `user_id`               bigint                         not null,
    `name`                  varchar(50) character set utf8mb4       default '' comment '账户名称',
    `address`               varchar(100) character set utf8mb4      default '' comment '账户地址',
    `private_key`           varchar(200) character set utf8mb4      default '' comment '私钥',
    `public_key`            varchar(200) character set utf8mb4      default '' comment '公钥',
    `mnemonic`              varchar(200) character set utf8mb4      default '' comment '助记词',
    `is_open_ddc`           bool                                    default true comment '是否接入官方ddc',
    `opb_key_type`          integer                                 default 3 comment '上传链账户地址模式:3,',
    `opb_chain_client_type` integer                                 default 2 comment '平台方账户为 1，终端账户为 2',
    `ops_platform_state`    integer                                 default 2 comment '运营方设置状态(0=未接入官方ddc 合约 1=冻结 2=已启用(未冻结) 3=冻结中 4=解冻中)',
    `platform_state`        integer                                 default 2 comment '平台方设置状态(0=未接入官方ddc 合约 1=冻结 2=已启用(未冻结) 3=冻 结中 4=解冻中)',
    `create_by`             varchar(64) character set utf8 not null default ' ' comment '创建人',
    `update_by`             varchar(64) character set utf8 not null default ' ' comment '修改人',
    `create_time`           datetime                                default null comment '创建时间',
    `update_time`           datetime                                default null comment '修改时间',
    `del_flag`              varchar(1) character set utf8mb4        default '0' comment '删除标志',
    primary key (`id`) using btree
) engine = innodb
  default charset = utf8mb4
  collate = utf8mb4_general_ci comment ='账户';

create index account_address_index
    on account (address);

create index account_name_index
    on account (name);

create index account_user_id_index
    on account (user_id);

-- -------------------------------
-- table structure for transaction
-- -------------------------------
create table transaction
(
    id           bigint auto_increment,
    block_number bigint                   null,
    block_hash   varchar(100)  default '' null,
    tx_hash      varchar(100)             null,
    to_address   varchar(100)  default '' null,
    from_address varchar(100)  default '' null,
    nonce        bigint                   null,
    tx_time      datetime                 null,
    gas_used     bigint                   null,
    gas_price    bigint                   null,
    tx_fee       bigint                   null,
    type         int           default 0  null,
    value        varchar(100)  default '' null,
    input        varchar(5000) default '' not null,
    constraint table_name_pk primary key (id)
);

create index table_name_tx_hash_index
    on transaction (tx_hash);

